'''
请设计一个装饰器，它可以作用于任何函数上，打印函数执行时间：
import time
def metric(fn):
start_time = time.time()
end_time = time.time()

print('耗时：{:.4f}s'.format(end_time - start_time))
return fn
'''
import time
def metric(fn):
    def printTime(*args, **kwargs):
        start_time = time.time()
        print('函数开始执行，当前时间为：{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        fn(*args, **kwargs)
        end_time = time.time()
        print('函数执行完毕，当前时间为：{}'.format(time.strftime('%Y-%m-%d %H:%M:%S')))
        print('耗时：{:.4f}s'.format(end_time - start_time))
    return printTime

@metric
def sumx2y(x,y):
    '''
    用于测试装饰器的方法，该方法实现x到y的累加
    :param x:
    :param y:
    :return:
    '''
    sum = 0
    for i in range(x,y+1):
        sum = sum + i
    print('x到y累加的和为{}'.format(sum))

#测试
sumx2y(1,10000000)


